public class test58 {
        public int lengthOfLastWord(String s) {
            int index = s.length() - 1;
            while (s.charAt(index) == ' ') {
                index--;
            }
            int wordLength = 0;
            while (index >= 0 && s.charAt(index) != ' ') {
                wordLength++;
                index--;
            }
            return wordLength;
        }
}
